<extend name="Common@Layout:hui-admin" />
<block name="title"><title>Administator管理后台</title></block>
<block name="style">
</block>

<block name="main">
<div class="pd-20">
	<form action="{:u('Contentadmin/edit_post')}" method="post" class="form form-horizontal validator_form close-dialog" id="form-article-add">
		<div id="tab-system" class="HuiTab">
			<div class="tabBar cl"><span>基本信息</span><span>图片详细</span><span>详细内容</span><span>文件附件</span><span>规格属性</span></div>
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">*</span>文章标题：</label>
					<div class="formControls col-8">
						<input type="text" class="input-text" value="{$info.title}" placeholder="请输入文章标题" id="" name="title" data-rule="文章标题:required;">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">简略标题：</label>
					<div class="formControls col-8">
						<input type="text" class="input-text" value="{$info.simple_title}" placeholder="请输入简略标题" id="" name="simple_title">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">*</span>文章类型：</label>
					<div class="formControls col-2"> 
						<span class="select-box">
							<select name="cid" class="select">
								{$catsoptions}
							</select>
						</span> 
					</div>
					<label class="form-label col-2">排序值：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text" value="{$info.listorder|default=0}" placeholder="" id="" name="listorder">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">关键词：</label>
					<div class="formControls col-10">
						<input type="text" class="input-text" value="{$info.keywords}" placeholder="" id="" name="keywords">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">文章摘要：</label>
					<div class="formControls col-10">
						<textarea name="desc" cols="" rows="" class="textarea"  placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="textarealength(this,200)">{$info.desc}</textarea>
						<p class="textarea-numberbar"><em class="textarea-length">0</em>/200</p>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">文章作者：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text" value="{$info.author}" placeholder="" id="" name="author">
					</div>
					<label class="form-label col-2">文章来源：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text" value="{$info.source}" placeholder="" id="" name="source">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">允许评论：</label>
					<div class="formControls col-2 skin-minimal">
						<div class="check-box">
							<input type="checkbox" name="ispinglun" value="1" <if condition="$info['ispinglun'] eq 1">checked</if>>
							<label for="checkbox-pinglun">&nbsp;</label>
						</div>
					</div>
					
					<label class="form-label col-2">保存至草稿：</label>
					<div class="formControls col-2 skin-minimal">
						<div class="check-box">
							<input type="checkbox" name="status" value="2"  <if condition="$info['status'] eq 2">checked</if>>
							<label for="checkbox-pinglun">&nbsp;</label>
						</div>
					</div>
				</div>
			</div>
			
			<div class="tabCon">
				<div class="pd-20">
					<table cellpadding="2"  class="mini-table" cellspacing="2" width="100%">
						<tbody>
							<tr>
								<th width="100">上传图片：</th>
								<td>
									<a href="javascript:;" id="uploadimg_m" class="mini-btn">批量上传</a>
								</td>
							</tr>
							<tr>
					             <th width="100">相册图集 ：</th>
					             <td>
									<fieldset class="blue pad-10">
						        	<legend>图片列表</legend>
						        	<div id="all-pics" style="float:left;">
						        		<volist name="info.imglist" id="img">
						        			<div class="gpic-box" id="up_{$img.img_id}">
						        				<span data-id="{$img.img_id}" <eq name="info['img_id']" value="$img['img_id']">class="tplr current"</eq> class="tplr" >
						        					<img src="{$img.url}" width="46" height="50" style="margin-top: 1px;">
						        				</span>
						        				<div class="gpic-btn-bar">
						        					<span class="gpic-btn-view show_img_info" data-id="{$img.img_id}" title="查看路径"><i>图片属性</i></span>|
						        					<span class="gpic-btn-delete" data-id="{$img.img_id}" title="删除图片"><i>删除图片</i></span>
						        				</div>
						        				<div style="display:none" id="img_detail_{$img.img_id}">
							        				<div class="img_detail">
								        				<input type="hidden" name="img_list_id[]" value="{$img.img_id}" />
								        				<lable>图片标题：<input type="text" name="img_list_title[]" class="img_title" value="{$img.title}" /></lable>
								        				<lable>替代文字：<input type="text" name="img_list_alt[]" class="img_alt" value="{$img.alt}" /></lable>
								        				<lable>跳转链接：<input type="text" name="img_list_redurl[]" class="img_redurl" value="{$img.redurl}" /></lable>
								        				<lable>
								        					跳转方式：
								        					<select name="img_list_target[]" class="img_target">
								        						<option value="_self" <eq name="img['target']" value="_self">selected</eq>>直接跳转</option>
								        						<option value="_blank" <eq name="img['target']" value="_target">selected</eq>>打开新窗口</option>
								        					</select>
								        				</lable>
							        				</div>
						        				</div>
						        			</div>
						        		</volist>
						        	</div>
									</fieldset>
									<div class="bk10"></div>
							  	</td>
					           </tr>
					           <tr>
					           	<th width="100">封面图预览：</th>
					           	<td>
					           		<div class="imgbox" id="spic_img">
					           			<if condition="$info['img_id']">
					           				<img src="{$info.fengmian.url}" />
					           			</if>
					           		</div>
					           		<span class="must_red">点击图片列表中的图片即可切换封面图设置</span>
					           		<input type="hidden" name="img_id" value="{$info.img_id}" id="img_id"/>
					           	</td>
					           </tr>
						</tbody>
					</table>
				</div>
			</div>
			
			<div class="tabCon">
				<div class="pd-20">
					<textarea name="content" style="width:800px;height:450px;visibility:hidden;">{$info.content}</textarea>
				</div>
			</div>
			
			<div class="tabCon">
				<div class="pd-20">
					<table cellpadding="2"  class="mini-table" cellspacing="2" width="100%">
						<tbody>
							<tr>
								<th width="100">上传附件：</th>
								<td>
									<a href="javascript:;" id="uploadButton_s" class="mini-btn">上传文件</a>
									<span class="must_red">允许上次的文件类型：'jpg', 'gif', 'png', 'jpeg','rar','zip','gz','doc','txt','docx','xls','xlsx','pdf'</span>
								</td>
							</tr>
							<tr>
					             <th width="100">附件：</th>
					             <td>
									<fieldset class="blue pad-10">
						        	<legend>附件列表</legend>
						        	<ul id="all-files" style="float:left;">
						        		<volist name="info['files']" id="file">
											<li id="file_li_{$file.file_id}">
												<span class="fl mr10">{$file.name}</span><a href="{$file.url}" target="_blank" class="fl">下载</a> <a href="javascript:;" class="fr delfile" data-id="{$file.file_id}">删除</a> 
												<input type="hidden" name="file_list_id[]" value="{$file.file_id}" />
												<div class="cb"></div>
											</li>
										</volist>
						        	</ul>
									</fieldset>
									<div class="bk10"></div>
							  	</td>
					           </tr>
						</tbody>
					</table>
				</div>
			</div>
			
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-2">规格模板：</label>
					<div class="formControls col-2"> 
						<notempty name="guige">
						<span class="select-box">
							<select name="standard" id="guige" class="select">
								<option value="">请选择</option>
								<volist name="guige" id="gg">
									<option value="{$gg.id}" <if condition="$gg['id'] eq $info['standard']['standard_id']">selected</if>>{$gg.title}</option>
								</volist>
								<if condition="$info['standard']['standard_id'] eq '-1'">
									<option value="-1" selected>模型已改变或已删除</option>
								</if>
							</select>
						</span> 
						<else/>
						<label class="form-label">还没有模板请先添加</label>
						</notempty>
					</div>
					<div class="formControls col-2">
						<a class="btn btn-primary radius" data-title="规格模型管理" _href="{:U('lists')}" onclick="parent.Hui_admin_tab(this)" href="javascript:;"><i class="Hui-iconfont"></i> 添加模板</a>
					</div>
				</div>
				<div class="row cl pro_stock" style="display:none;">
					<label class="form-label col-2">规格：</label>
					<div class="formControls col-8 pro_stock_content" data-data='{$info["standard"]["standard_content"]}'> 
						
					</div>
				</div>
			</div>
		</div>
		
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<input type="hidden" name="id" value="{$info.id}">
				<button class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存并提交审核</button>
				<button onClick="parent.close_iframe_dialog();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</div>
</block>

<block name="script">
<css href="/Public/Sea/modules/kindeditor/src/default.css,/Public/Sea/modules/kindeditor/css/upload.css" />
<js href="/Public/Sea/modules/kindeditor/src/kindeditor-min.js,/Public/Sea/modules/kindeditor/src/lang/zh_CN.min.js" />
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	$.Huitab("#tab-system .tabBar span","#tab-system .tabCon","current","click","0");
	
	//规格模型
	//var guige;
	var guige = $("#guige").val();
	if(guige>0 || guige == -1){
		$("#guige").trigger("change");
	}
	
});

var config = {appid:'{$app['app_id']}',appkey:'{$app['app_key']}'};
var uploadurl = '/material/image/upload';

var editor = KindEditor.editor({
	uploadJson : uploadurl,
	allowFileManager : true,
	fileManagerJson : config.fileManagerJson,
});
var editor1 = KindEditor.create('textarea[name="content"]',{
	uploadJson : uploadurl,
	allowFileManager : true,
	fileManagerJson : config.fileManagerJson,
	afterBlur: function(){this.sync();}
});
$('#uploadimg_m').click(function() {
	
	editor.loadPlugin('multiimage', function() {
		editor.plugin.multiImageDialog({
			clickFn : function(urlList) {
				var div = $('#all-pics');
				$.each(urlList, function(i, data) {
					//data.id = i; //demo,实际应用中删除
					if(!$('.gpic-box span.current').html() && i == 0){
						var html ='<div class="gpic-box" id="up_'+data.id+'">' 
						+'<span data-id="'+data.id+'" class="current tplr"><img src="' + data.url + '" width="46" height="50" style="margin-top: 1px;"></span>' 
						+'<div class="gpic-btn-bar">'  
						+'<span class="gpic-btn-view show_img_info" data-id="'+data.id+'" title="查看路径"><i>查看路径</i></span>|<span class="gpic-btn-delete" data-id="'+data.id+'" title="删除图片"><i>删除图片</i></span>' 
						+'</div>'
						+'<div style="display:none" id="img_detail_'+data.id+'">'
						+'<div class="img_detail">'
						+'<input type="hidden" name="img_list_id[]" value="'+data.id+'" />'
						+'<label>图片标题： <input type="text" name="img_list_title[]" class="img_title" value="" /></label><br><br>'
						+'<label>替代文字： <input type="text" name="img_list_alt[]" class="img_alt" value="" /></label><br><br>'
						+'<label>跳转链接： <input type="text" name="img_list_redurl[]" class="img_redurl" value="" /></label><br><br>'
						+'<label>跳转方式： <select name="img_list_target[]" class="img_target"><option value="_self">直接跳转</option><option value="_blank">打开新窗口</option></select></lable>'
						+'</div>'
						+'</div>'
						+'</div>';
						
						$('#img_id').val(data.id);
						$('#spic_img').html('<img src="'+data.url+'"/>');
					}else{
						var html ='<div class="gpic-box" id="up_'+data.id+'">' 
						+'<span data-id="'+data.id+'" class="tplr"><img src="' + data.url + '" width="46" height="50" style="margin-top: 1px;"></span>' 
						+'<div class="gpic-btn-bar">'  
						+'<span class="gpic-btn-view show_img_info" data-id="'+data.id+'" title="查看路径"><i>查看路径</i></span>|<span class="gpic-btn-delete" data-id="'+data.id+'" title="删除图片"><i>删除图片</i></span>' 
						+'</div>'  
						+'<div style="display:none" id="img_detail_'+data.id+'">'
						+'<div class="img_detail">'
						+'<input type="hidden" name="img_list_id[]" value="'+data.id+'" />'
						+'<label>图片标题： <input type="text" name="img_list_title[]" class="img_title" value="" /></label><br><br>'
						+'<label>替代文字： <input type="text" name="img_list_alt[]" class="img_alt" value="" /></label><br><br>'
						+'<label>跳转链接： <input type="text" name="img_list_redurl[]" class="img_redurl" value="" /></lable><br><br>'
						+'<label>跳转方式： <select name="img_list_target[]" class="img_target"><option value="_self">直接跳转</option><option value="_blank">打开新窗口</option></select></lable>'
						+'</div>'
						+'</div>'
						+'</div>';
					}
					div.append(html);
					imgInti();
				});
				editor.hideDialog();
				
			}
		});
	});
	
});

function imgInti(){
	$('.gpic-btn-delete').click(function(){
		var $this = $(this);
		var imgid = $this.attr('data-id');
		var asker = layer.confirm('是否确定删除?', function(){
			divid = "#up_"+imgid;
			var delurl = '/material/image/del';
			$.get(delurl+'/ids/'+imgid,function(data){
				if(data['status'] == 1){
					$(divid).remove();
					if($('#img_id').val() == imgid){
						$('#img_id').val('');
						$('#spic_img').html('');
					}
				}else{
					alert('图片无法删除');
				}
			},'json');
			
			
			layer.close(asker);
		});
	});

	$('.tplr').click(function(){
		var $this = $(this);
		imgid = $this.attr('data-id');
		var divid = "#up_"+imgid;
		var img_src = $("#up_"+imgid+" > span > img").attr('src');
		$('#img_id').val(imgid);
		$(".gpic-box > span").removeClass('current');
		$("#up_"+imgid+" > span").eq(0).addClass('current');
		$('#spic_img').html('<img src="'+img_src+'"/>');
	});

	$('.show_img_info').click(function(){
		var id = 'img_detail_'+$(this).attr('data-id');
		layer.open({
		    type: 1,
		    maxmin: true,
		    title: '图片属性',
		    area: ['400px', '300px'],
		    content:$('#'+id),
			btns: 2,
		    btn: ['确定','关闭'],
		    yes: function(index){
	            var title = $('#xubox_layer'+index+' .img_detail .img_title').val();
	            var alt = $('#xubox_layer'+index+' .img_detail .img_alt').val();
	            $('#'+id+' .img_detail .img_title').attr('value',title);
	            $('#'+id+' .img_detail .img_alt').attr('value',alt);
	            layer.close(index);
	        },
	        no: function(index){
	            layer.close(index);
	        }
		});
	});
}

imgInti();

var uploadurl = '/material/file/upload';
var editor2 = KindEditor.editor({
	uploadJson : uploadurl,
	allowFileManager : false,
	afterUpload : function(url,data,name) {
		if (data.error === 0) {
			//currentFileId = data.file_id;
			var div = $("#all-files");
			var html = '<li id="file_li_'+data.file_id+'">'+
						'<span style="float:left;margin-right:10px;">'+data.file_name+'</span><a href="'+data.file_path+'" target="_blank" style="float:left;">下载</a> <a href="javascript:;" data-id="'+data.file_id+'" style="float:right" class="delfile">删除</a>'+ 
						'<input type="hidden" name="file_list_id[]" value="'+data.file_id+'" />'+
						'<div style="clear:both"></div>'+
					'</li>';
			div.append(html);
			fileInit();
		} else {
			alert(data.msg);
		}
	}
});

//点击打开上传文件窗口
$('#uploadButton_s').click(function() {

	editor2.loadPlugin('insertfile', function() {
		editor2.plugin.fileDialog({
			clickFn : function(url, title) {
				editor2.hideDialog();
			}
		});
	});

});

function fileInit(){
	$('.delfile').click(function(){
		var fileid = $(this).attr('data-id');
		var asker = layer.confirm('是否确定删除?', function(){
			divid = "#file_li_"+fileid;
			var delurl = '/material/file/del';
			$.get(delurl+'/ids/'+fileid,function(data){
				if(data['status'] == 1){
					$(divid).remove();
				}else{
					alert('图片无法删除');
				}
			},'json');

			layer.close(asker);
		});
	});
}
fileInit();

$("#guige").change(function(){
	var id = $(this).val();
	if(id>0 || id == '-1'){
		//var standard = $(".pro_stock_content").attr("data-data");
		var data;
		var articleid = $("input[name=id]").val();
		data = {id:id,articleid:articleid};
		$.post('/Material/Contentadmin/autostandard',data,function(res){
			if(res.status){
				$('.pro_stock').show();
				$('.pro_stock_content').html(res.info);
			}
		})
	}else{
		$('.pro_stock').hide();
		$('.pro_stock_content').html('');
	}
})
</script>
</block>